package com.elitetyc.customview.custom;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.blankj.utilcode.util.ConvertUtils;
import com.elitetyc.customview.R;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by elitetyc on 2019/6/11.
 * Describe:
 */
public class TwoButtonDialog extends Dialog {
    private CircleImageView iv_dialog_type;
    private TextView tv_message,tv_btn_sure,tv_btn_cancel,tv_message_small;


    public TwoButtonDialog(Context context,DialogEnum type,String message){
        this(context,type,message,"确认","取消");
    }

    public TwoButtonDialog(Context context, DialogEnum type, String message, String btnSureText,String btnCanelText){
        this(context,type,message,null,btnSureText,btnCanelText);

    }

    public TwoButtonDialog(Context context, String message,String smallMessage){
        this(context,message,smallMessage,"取消","删除");
    }

    public TwoButtonDialog(Context context, String message,String smallMessage, String btnSureText,String btnCanelText){
        this(context,DialogEnum.DIALOG_NO_ICON,message,smallMessage,btnSureText,btnCanelText);
    }

    public TwoButtonDialog(Context context, DialogEnum type, String message,String smallMessage, String btnSureText,String btnCanelText) {
        super(context,R.style.MyDialog);
        setContentView(R.layout.dialog_two_button);

        iv_dialog_type = findViewById(R.id.iv_dialog_type);
        tv_message = findViewById(R.id.tv_message);
        tv_btn_sure = findViewById(R.id.tv_btn_sure);
        tv_btn_cancel = findViewById(R.id.tv_btn_cancel);
        tv_message_small = findViewById(R.id.tv_message_small);
        tv_message.setPadding(0,ConvertUtils.dp2px(15),0,ConvertUtils.dp2px(15));

//        根据类型显示不同的图标
        switch (type){
            case DIALOG_OK:
                break;
            case DIALOG_TIMEING:
                break;
            case DIALOG_ERROR:
                break;
            case DIALOG_WRNING:
                break;
            case DIALOG_NO_ICON:
//                无图标
                iv_dialog_type.setVisibility(View.GONE);
                if (smallMessage!=null){
                    tv_message.setPadding(0,ConvertUtils.dp2px(15),0,ConvertUtils.dp2px(5));
                    tv_message_small.setText(smallMessage);
                    tv_message_small.setVisibility(View.VISIBLE);
                }
                break;
            default:
                break;
        }
        tv_message.setText(message);
        tv_btn_sure.setText(btnSureText);
        tv_btn_cancel.setText(btnCanelText);

        Window dialogWindow = getWindow();
        Activity activity = (Activity) context;
        WindowManager m = activity.getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = getWindow().getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.75); // 宽度设置为屏幕的0.95
        dialogWindow.setAttributes(p);
//        点击屏幕外不消失，点击返回键消失
        setCanceledOnTouchOutside(false);
    }

    public void setSureClick(View.OnClickListener onClickListener){
        tv_btn_sure.setOnClickListener(onClickListener);
    }

    public void setCancelClick(View.OnClickListener onClickListener){
        tv_btn_cancel.setOnClickListener(onClickListener);
    }


}
